/**
 * This class is an implementation of a warehouse management
 */

/**
 * @author Maximilian Csuk
 * @author Bernhard Denner
 * @author Konrad Paumann
 *
 * $Revision: 52 $
 * $Date: 2007-10-17 21:22:30 +0000 (Wed, 17 Oct 2007) $
 */
import java.util.*;


public class WarehouseManagement {
	/**
	 * contains stored products
	 */
	protected TreeMap<String, Product> assortment;
	
	/**
	 * constructor
	 */
	WarehouseManagement() {
		assortment = new TreeMap<String, Product>();
	}
	/**
	 * returns a product
	 * 
	 * @param sdescription
	 * @return product
	 * @throws ProductException
	 */
	public Product getElement (String sdescription)
			throws ProductException {
		if (!assortment.containsKey(sdescription))
			throw new ProductException("Produkt nicht im Sortiment");
		
		return assortment.get(sdescription);
	}
	/**
	 * add a product into the assortment
	 * 
	 * @param sdescription
	 * @param description
	 * @param price
	 * @param amount
	 * @throws ProductException
	 */
	public void addProduct(String sdescription, String description, int price, int amount) 
			throws ProductException {
		if (assortment.containsKey(sdescription))
			throw new ProductException("Produkt bereits enthalten");
		else
			assortment.put(sdescription, new Product(sdescription, description,
					price, amount));
	}
	
	/**
	 * lists all products
	 */
	public void listProducts() {
		System.out.println(Product.getOutputHeader());
		Iterator<String> it = assortment.keySet().iterator();
		while (it.hasNext()) {			
			System.out.println(assortment.get(it.next()));
		}
	}
	
	/**
	 * returns a product iterator
	 */
	public Iterator<Product> getProductIterator() {
		return assortment.values().iterator();
	}
	
	/**
	 * alters the amount of a product when it gets to the warehouse
	 * 
	 * @param sdescription
	 * @param count
	 * @throws ProductException
	 */
	
}
